package com.biyabi.controller;

import com.biyabi.entity.Catelog;
import com.biyabi.pojo.CatelogData;
import com.biyabi.pojo.CatelogsData;
import com.biyabi.pojo.Result;
import com.biyabi.service.CatelogService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/back/catelog")
public class CatelogController {
    @Resource
    private CatelogService catelogService;
    @RequestMapping("/findAll")
    public CatelogsData findAll(Integer page, Integer rows, String columnName, String columnValue){
        return catelogService.findAll(page,rows,columnName,columnValue);
    }
    @RequestMapping("/findAllCatelog")
    public List<CatelogData> findAllCatelog(){
        return catelogService.findAllCatelog();
    }
    @RequestMapping("/findAllLastCatelog")
    public List<Catelog> findAllLastCatelog(){
        return catelogService.findAllLastCatelog();
    }
    @RequestMapping("/findAllCatelogWithoutMyself")
    public List<CatelogData> findAllCatelogWithoutMyself(String id){
        return catelogService.findAllCatelogWithoutMyself(id);
    }
    @RequestMapping("/add")
    public Result add(Catelog catelog, MultipartFile addCatelogLogoFile, HttpServletRequest request){
        Result result = new Result();
        try{
            catelogService.insert(catelog,addCatelogLogoFile,request);
            result.setStatus(true);
            result.setMessage("添加供货商成功！");
        }catch(Exception e){
            result.setStatus(false);
            result.setMessage("添加供货商失败！");
        }
        return result;
    }
    @RequestMapping("/update")
    public Result update(Catelog catelog, MultipartFile updateCatelogLogoFile, HttpServletRequest request){
        Result result = new Result();
        try{
            catelogService.update(catelog,updateCatelogLogoFile,request);
            result.setStatus(true);
            result.setMessage("更新供货商成功！");
        }catch(Exception e){
            result.setStatus(false);
            result.setMessage("更新供货商失败！");
        }
        return result;
    }
    @RequestMapping("/findOne")
    public Catelog findOne(String id){
        return catelogService.findOne(id);
    }

}
